#! /usr/local/bin/ruby

# This class finds files that may be exact duplicates;
# Creates a hash table of hexdigests (keys) and file paths (values). 

require 'digest/sha1'

class FilesByDigest < Hash
  def << file_name
    if File.file?(file_name)
      hexdigest = Digest::SHA1.hexdigest(File.read(file_name))
      self[hexdigest] ||= []
      self[hexdigest] << file_name
    end
  end
end
